﻿using DataTransformationTasks.BaseDriver;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace DataTransformationTasks.TcpClientDirver
{
    public class TcpClientService : BackgroundService
    {
        private readonly ILogger _logger;

        public TcpClientService(ILogger<TcpClientService> logger, ILoggerFactory loggerFactory)
        {
            _logger = logger;
            LoggerFactory.SetFactory(loggerFactory);
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation($"TcpClientService ExecuteAsync Started At:{DateTime.Now:yyyy-MM-dd HH:mm:ss}");

            var config = Bootstrap.Start(new string[] { });
            var machines = await Machines.CreateMachines(config);
            await machines.RunAsync(stoppingToken);
        }
    }
}
